<template>
  <div class="app-container">
    <div class="filter-container default-box">
      <span>关键字：</span>
      <el-input v-model="listQuery.title" placeholder="请输入关键字" style="width: 240px;" class="filter-item" />
      <span style="padding-left: 100px;">类型：</span>
      <el-select v-model="typevalue" placeholder="请选择">
        <el-option v-for="item in typeoptions" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <span style="padding-left: 100px;">状态：</span>
      <el-select v-model="statusvalue" placeholder="请选择">
        <el-option v-for="item in statusoptions" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>
      <el-button class="filter-item" type="primary" icon="el-icon-search" style="margin-left:50px" round>
        查询
      </el-button>
      <el-button class="filter-item" icon="el-icon-refresh-right" round>
        重置
      </el-button>
    </div>
    <div class="default-box">
      <div class="filter-container">
        <el-button class="filter-item" type="primary" icon="el-icon-plus" round @click="createDialog = true;isadd = true">
          新增
        </el-button>
      </div>
      <el-table
        :key="tableKey"
        v-loading="listLoading"
        :data="list"
        fit
        highlight-current-row
        style="width: 100%;"
      >
        <el-table-column label="标题" width="150">
          <template>
            <span>测试04</span>
          </template>
        </el-table-column>
        <el-table-column label="类型" width="150">
          <template>
            <span class="warning-color">虚拟</span>
          </template>
        </el-table-column>
        <el-table-column label="已售票数" width="150">
          <template>
            <span>
              10
            </span>
          </template>
        </el-table-column>
        <el-table-column label="总票数" width="150">
          <template>
            <span>
              10
            </span>
          </template>
        </el-table-column>
        <el-table-column label="售卖" width="150">
          <template>
            <span class="success-color">已上架</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="150">
          <template>
            <span class="success-color">已开奖</span>
          </template>
        </el-table-column>
        <el-table-column label="中奖票号" width="200">
          <template>
            <span>
              e9R48R9EzJ3EqABh
            </span>
          </template>
        </el-table-column>
        <el-table-column label="虚拟奖励" width="300">
          <template>
            <span>
              积分：10.0000 贡献值：10.0000 其他：10
            </span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="700" class-name="small-padding fixed-width">
          <template>
            <el-button type="warning" round @click="handleDelete('randomdraw','随机开奖')">随机开奖</el-button>
            <el-button type="primary" round @click="handleDelete('reissue','再开一期')">再开一期</el-button>
            <el-button type="primary" round @click="ticketDialog=true">票号</el-button>
            <el-button type="success" round @click="delivergoodsDialog=true">发货</el-button>
            <el-button type="warning" round @click="createDialog = true;isadd = true">修改</el-button>
            <el-button type="danger" round @click="handleDelete('del','删除该商品')">删除</el-button>
            <el-button type="danger" round @click="handleDelete('close','关闭该商品')">关闭</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
    <!-- 展示新增、编辑对话框 -->
    <el-dialog
      :title="isadd?'新增福利商品':'编辑福利商品'"
      :visible.sync="createDialog"
      width="50%"
      custom-class="operate-dialog"
      top="10vh"
      center
    >
      <el-form :model="oprateform" label-width="120px">
        <el-form-item label="标题">
          <el-input v-model="oprateform.name" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="总票数">
          <el-input v-model="oprateform.name" placeholder="请输入总票数" />
        </el-form-item>
        <el-form-item label="组图">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :file-list="fileList"
            list-type="picture"
          >
            <el-button type="primary">上传图片</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="奖品模式">
          <el-radio-group v-model="oprateform.prizemodel">
            <el-radio :label="1">实物</el-radio>
            <el-radio :label="2">虚拟</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="奖励积分">
          <el-input v-model="oprateform.name" placeholder="请输入奖励积分" />
        </el-form-item>
        <el-form-item label="奖励互帮值">
          <el-input v-model="oprateform.name" placeholder="请输入奖励互帮值" />
        </el-form-item>
        <el-form-item label="其他奖励">
          <el-input v-model="oprateform.name" placeholder="请输入其他奖励" />
        </el-form-item>
        <el-form-item label="内容">
          <tinymce v-model="content" menubar="false" :height="300" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleResetOperate">重置</el-button>
        <el-button type="primary" @click="handleOperate">提交</el-button>
      </span>
    </el-dialog>
    <!--  票号对话框 -->
    <el-dialog
      title="票号"
      :visible.sync="ticketDialog"
      width="80%"
      custom-class="operate-dialog main-bagcolor"
      top="5vh"
      center
    >
      <TicketNumber />
    </el-dialog>
    <!--  发货对话框 -->
    <el-dialog
      title="发货"
      :visible.sync="delivergoodsDialog"
      width="80%"
      custom-class="operate-dialog main-bagcolor"
      top="30vh"
      center
    >
      <DeliverGoods />
    </el-dialog>
  </div>
</template>

<script>
import DeliverGoods from './components/deliver-goods'
import TicketNumber from './components/ticket-number'
import Tinymce from '@/components/Tinymce'
import { fetchList } from '@/api/article'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'Adminrole',
  components: { Pagination, Tinymce, DeliverGoods, TicketNumber },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        title: ''
      },
      status: true,
      typeoptions: [{ // 类型选择项组
        value: '',
        label: '不限'
      }, {
        value: '实物商品',
        label: '实物商品'
      }, {
        value: '虚拟商品',
        label: '虚拟商品'
      }],
      typevalue: '', // 选择的类型
      statusoptions: [{ // 状态选择项组
        value: '',
        label: '不限'
      }, {
        value: '未开奖',
        label: '未开奖'
      }, {
        value: '已开奖',
        label: '已开奖'
      }, {
        value: '未成功开奖',
        label: '未成功开奖'
      }],
      statusvalue: '', // 状态的类型
      isadd: true, // 是新增 否编辑
      createDialog: false, // 是否展示新增、编辑对话框
      ticketDialog: false, // 是否展示票号对话框
      delivergoodsDialog: false, // 是否展示发货对话框
      oprateform: { // 新增、编辑条件
        name: '',
        describe: '',
        prizemodel: 2
      },
      content: ``, // 富文本内容
      fileList: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.items
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    // 新增、编辑
    handleOperate() {
      this.createDialog = false
    },
    // 重置新增，编辑内容
    handleResetOperate() {
      this.oprateform = {
        name: '',
        describe: ''
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    },
    // 删除
    handleDelete(type, tip) {
      this.$confirm('确定要' + tip + '吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        center: true,
        customClass: 'text-center'
      }).then(() => {
        this.$notify({
          title: '成功',
          message: '删除成功',
          type: 'success',
          duration: 2000
        })
        // this.$message({
        //   type: 'success',
        //   message: '删除成功!'
        // })
      }).catch(() => {

      })
      // this.list.splice(index, 1)
    }
  }
}
</script>
<style scoped>
  [class^=el-icon-], [class*=" el-icon-"]{
    font-size: 16px;
  }
  .small-padding i{
    margin-right: 12px;
  }
  .small-padding i:last-child{
    margin-right: 0px;
  }
  ::v-deep .filter-container .el-input--medium .el-input__inner{
    width: 240px;
  }
</style>
